{{define "urls.html" -}}
{{template "header.html" . -}}
{{template "sidebar.html" . -}}
<div class="pusher">
{{template "admin-left-menu.html" . -}}
{{template "admin-top-menu.html" . -}}
<div id="admin-right-content" class="ui basic segment">  
  <div class="ui grid stackable padded">
    <div class="column">
      <table class="ui celled striped table">
        <thead>
          <tr>
            <th colspan="3">
              <form id="form-search-url" action="/admin/urls" method="get">
                <div class="ui labeled action input">
                  <div class="ui label">{{.prefix}}</div>
                  <input name="url" type="text" value="{{.url}}" placeholder="短链接">                
                </div>
                <button class="ui teal right labeled icon button" type="submit"><i class="search icon"></i>查询</button>
                <a class="ui teal right labeled icon button" href="/admin/urls"><i class="undo alternate icon"></i>重置</a>                 
              </form>             
            </th>
            <th colspan="7"><button id="btn-new-shorturl-modal" class="ui primary button">新建短链接</button></th>
          </tr>
          <tr>            
            <th>短链接</th>
            <th class="center aligned collapsing">生成时间</th>
            <th>备注信息</th>  
            <th>打开方式</th>
            <th class="center aligned collapsing">是否有效</th>                      
            <th class="center aligned">目标链接</th>
            <th class="center aligned">操作</th>       
          </tr>
        </thead>
        <tbody>
          {{range .shortUrls}}
          <tr {{if not .Valid}}class="negative"{{end}}>
            <td class="collapsing"><a href="{{$.prefix}}{{.ShortUrl}}" target="_blank">{{.ShortUrl}}</a></td>
            <td class="center aligned collapsing">{{.CreatedAt | date "2006-01-02 15:04:05"}}</td>
            <td>{{.Memo.String}}</td>
            <td>
              {{if eq 0 .OpenType}}
              不限制
              {{else if eq 1 .OpenType}}
              微信内打开
              {{else if eq 2 .OpenType}}
              钉钉内打开
              {{else if eq 3 .OpenType}}
              iPhone 打开
              {{else if eq 4 .OpenType}}
              Android 打开
              {{else if eq 5 .OpenType}}
              iPad 打开
              {{else if eq 6 .OpenType}}
              Safari 浏览器
              {{else if eq 7 .OpenType}}
              Chrome 浏览器
              {{else if eq 8 .OpenType}}
              Firefox 浏览器
              {{else}}
                不确定
              {{end}}
            </td>
            <td class="center aligned">{{.Valid}}</td>            
            <td class="center aligned collapsing"><a href="{{.DestUrl}}" target="_blank">打开链接</a></td>                                   
            <td class="center aligned">
              {{if .Valid}} 
              <a href="javascript:enable_url('{{.ShortUrl}}',false)">禁用</a> 
              {{else}}
              <a href="javascript:enable_url('{{.ShortUrl}}',true)">开启</a> 
              {{end}}
              | <a href="javascript:copy_url('{{$.prefix}}{{.ShortUrl}}')">复制</a>
              | <a href="javascript:delete_url('{{.ShortUrl}}')">删除</a>
              | <a href="/admin/stats?url={{.ShortUrl}}" target="_blank">统计数据</a></td>            
          </tr>
          {{end}}
        </tbody>
        <tfoot>
          <tr>            
            <th colspan="10" class="center aligned">
              {{if not .first_page}}
              <a class="ui small labeled icon button" href="/admin/urls?url={{.url}}&page={{sub .page 1}}"><i class="arrow alternate circle left outline icon"></i>上一页</a>
              {{end}}
              {{if not .last_page}}
              <a class="ui small labeled icon button" href="/admin/urls?url={{.url}}&page={{add .page 1}}"><i class="arrow alternate circle right outline icon"></i>下一页</a>              
              {{end}} 
            </th>
          </tr>
        </tfoot>
      </table>
    </div>
  </div><!--end fo grid-->
</div><!--end of segment-->
</div><!--end of pusher-->
<div id="new-shorturl-modal"  class="ui modal">  
  <i class="close icon"></i>
  <div class="header">新建短链接</div>
  <div class="content">   
    <div class="description">      
      <div class="ui form">        
        <div class="field">
          <label>目标链接</label>
          <textarea id="input_dest_url" name="dest_url" rows="1"></textarea>
        </div>
        <div class="field">
          <label>打开方式</label>
          <select id="input_open_type" name="open_type" class="ui search dropdown" name="open_type">
            <option value="0">不限制</option>
            <option value="1">微信内打开</option>
            <option value="2">钉钉内打开</option>
            <option value="3">iPhone 打开</option>
            <option value="4">Android 打开</option>
            <option value="5">iPad 打开</option>
            <option value="6">Safari 浏览器</option>
            <option value="7">Chrome 浏览器</option>
            <option value="8">Firefox 浏览器</option>
          </select>
        </div>
        <div class="field">
          <label>备注</label>
          <textarea id="input_demo" name="memo" rows="2"></textarea>
        </div>
      </div>      
    </div>
  </div>
  <div class="actions">
    <div class="ui black deny button">
      放弃
    </div>
    <div id="btn-gen-short-url" class="ui primary right labeled icon button">
      确认新建
      <i class="checkmark icon"></i>
    </div>
  </div>
</div>
{{end -}}